package com.sl.u_push_plugin

import android.app.Application
import android.content.Context
import org.android.agoo.huawei.HuaWeiReceiver
import org.android.agoo.huawei.HuaWeiRegister
import org.android.agoo.mezu.MeizuRegister
import org.android.agoo.oppo.OppoRegister
import org.android.agoo.vivo.VivoRegister
import org.android.agoo.xiaomi.MiPushRegistar

class OtherPlatformBuilder {
    private var platFormInit: OtherPlatFormInit

    private constructor(context: Context) {
        platFormInit = OtherPlatFormInit(context)
    }

    companion object {
        fun Builder(context: Context): OtherPlatformBuilder {
            return OtherPlatformBuilder(context)
        }
    }

    fun initOppo(key: String, secret: String):OtherPlatformBuilder {
        platFormInit?.run {
            oppoSignKey = key
            oppoSecret = secret
        }
        return this
    }

    fun initXiaoMi(id: String, key: String):OtherPlatformBuilder {
        platFormInit?.run {
            xiaoMiSignKey = id
            xiaoMiSecret = key
        }
        return this
    }

    fun initMeiZu(id:String,key:String):OtherPlatformBuilder{
        platFormInit?.run {
            meiZuSignKey = id
            meiZuSecret = key
        }
        return this
    }

    fun initHuawei():OtherPlatformBuilder{
        platFormInit?.run {
            registerHuawei = true
        }
        return this
    }

    fun initVivo():OtherPlatformBuilder{
        platFormInit?.run {
            registerVivo = true
        }
        return this
    }

    fun build(): OtherPlatFormInit {
        return platFormInit;
    }


    class OtherPlatFormInit(var context: Context) {
        var oppoSignKey = ""
        var oppoSecret = ""
        var xiaoMiSignKey = ""
        var xiaoMiSecret = ""
        var meiZuSignKey = ""
        var meiZuSecret = ""
        var registerHuawei = false;
        var registerVivo = false;

        fun register() {
            registerOppo()
            registerXiaoMi()
            registerMeizu()
            registerVivo()
            registerHuawei()
        }

        private fun registerHuawei(){
            if(registerHuawei){
                HuaWeiRegister.register(context as Application)
            }

        }

        private fun registerVivo() {
            if(registerVivo){
                VivoRegister.register(context)
            }
        }

        private fun registerMeizu() {
            if(meiZuSignKey.isNotEmpty()){
                MeizuRegister.register(context,meiZuSignKey,meiZuSecret)
            }

        }

        private fun registerXiaoMi() {
            if(xiaoMiSignKey.isNotEmpty()){
                MiPushRegistar.register(context, xiaoMiSignKey, xiaoMiSecret)
            }
           
        }

        private fun registerOppo() {
            if (oppoSignKey.isNotEmpty()) {
                OppoRegister.register(context, oppoSignKey, oppoSecret)
            }
        }

    }
}